<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="邮箱" prop="email">-->
<!--        <el-input-->
<!--          v-model="queryParams.email"-->
<!--          placeholder="请输入邮箱"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="头像" prop="logo">-->
<!--        <el-input-->
<!--          v-model="queryParams.logo"-->
<!--          placeholder="请输入头像"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="昵称" prop="nickName">-->
<!--        <el-input-->
<!--          v-model="queryParams.nickName"-->
<!--          placeholder="请输入昵称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="密码" prop="password">-->
<!--        <el-input-->
<!--          v-model="queryParams.password"-->
<!--          placeholder="请输入密码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="密码盐" prop="salt">-->
<!--        <el-input-->
<!--          v-model="queryParams.salt"-->
<!--          placeholder="请输入密码盐"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="交易密码" prop="txPassword">-->
<!--        <el-input-->
<!--          v-model="queryParams.txPassword"-->
<!--          placeholder="请输入交易密码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="邀请码" prop="inviteCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.inviteCode"-->
<!--          placeholder="请输入邀请码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="真实名称" prop="realName">-->
<!--        <el-input-->
<!--          v-model="queryParams.realName"-->
<!--          placeholder="请输入真实名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身份证号" prop="cardNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.cardNo"-->
<!--          placeholder="请输入身份证号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身份证正面照" prop="cardFrontUrl">-->
<!--        <el-input-->
<!--          v-model="queryParams.cardFrontUrl"-->
<!--          placeholder="请输入身份证正面照"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="身份证反面照" prop="cardBackUrl">-->
<!--        <el-input-->
<!--          v-model="queryParams.cardBackUrl"-->
<!--          placeholder="请输入身份证反面照"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="手持照" prop="holdCardUrl">-->
<!--        <el-input-->
<!--          v-model="queryParams.holdCardUrl"-->
<!--          placeholder="请输入手持照"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="守护星级等级" prop="holdLevel">-->
<!--        <el-input-->
<!--          v-model="queryParams.holdLevel"-->
<!--          placeholder="请输入守护星级等级"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="矿工等级" prop="mineLevel">-->
<!--        <el-input-->
<!--          v-model="queryParams.mineLevel"-->
<!--          placeholder="请输入矿工等级"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="平台代数" prop="seniority">-->
<!--        <el-input-->
<!--          v-model="queryParams.seniority"-->
<!--          placeholder="请输入平台代数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否开启签到 0否 1是 实名认证通过后开启" prop="isSign">-->
<!--        <el-input-->
<!--          v-model="queryParams.isSign"-->
<!--          placeholder="请输入是否开启签到 0否 1是 实名认证通过后开启"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['api:user:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['api:user:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['api:user:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['api:user:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="${comment}" align="center" prop="id" />-->
      <el-table-column label="手机号" align="center" prop="mobile" />
<!--      <el-table-column label="邮箱" align="center" prop="email" />-->
<!--      <el-table-column label="头像" align="center" prop="logo" />-->
<!--      <el-table-column label="昵称" align="center" prop="nickName" />-->
<!--      <el-table-column label="密码" align="center" prop="password" />-->
<!--      <el-table-column label="密码盐" align="center" prop="salt" />-->
<!--      <el-table-column label="交易密码" align="center" prop="txPassword" />-->
      <el-table-column label="邀请码" align="center" prop="inviteCode" />
      <el-table-column label="真实名称" align="center" prop="realName" />
      <el-table-column label="身份证号" align="center" prop="cardNo" />
<!--      <el-table-column label="身份证正面照" align="center" prop="cardFrontUrl" />-->
<!--      <el-table-column label="身份证反面照" align="center" prop="cardBackUrl" />-->
      <el-table-column
        prop="cardPositive"
        popper-class="popperBox"
        header-align="center"
        align="center"
        width="150px"
        label="身份证正面照">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="click">
            <img :src="scope.row.cardFrontUrl" style="max-height: 300px;max-width: 500px" />
            <img slot="reference" :src="scope.row.cardFrontUrl" :alt="scope.row.cardFrontUrl" style="max-height: 50px;max-width: 50px">
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
        prop="cardPositive"
        popper-class="popperBox"
        header-align="center"
        align="center"
        width="150px"
        label="身份证反面照">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            title=""
            trigger="click">
            <img :src="scope.row.cardBackUrl" style="max-height: 300px;max-width: 500px" />
            <img slot="reference" :src="scope.row.cardBackUrl" :alt="scope.row.cardBackUrl" style="max-height: 50px;max-width: 50px">
          </el-popover>
        </template>
      </el-table-column>
<!--      <el-table-column label="手持照" align="center" prop="holdCardUrl" />-->
<!--      <el-table-column label="认证状态 0待认证 1审核中 2审核通过 3审核拒绝" align="center" prop="authStatus" />-->
      <el-table-column prop="authStatus" label="认证状态" width="100px">
        <template scope="scope">
          <span v-if="scope.row.authStatus=== 0 " >待认证</span>
          <span v-else-if="scope.row.authStatus === 1" >审核中</span>
          <span v-else-if="scope.row.authStatus === 2" >审核通过</span>
          <span v-else-if="scope.row.authStatus === 3" >审核拒绝</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="用户状态 1可用 2冻结  3禁用" align="center" prop="status" />-->
      <el-table-column prop="status" label="用户状态" align="center">
        <template scope="scope">
          <span v-if="scope.row.status=== 1 " >可用</span>
          <span v-else-if="scope.row.status === 2" >冻结</span>
          <span v-else-if="scope.row.status === 3" >禁用</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="守护星级等级" align="center" prop="holdLevel" />-->
<!--      <el-table-column label="矿工等级" align="center" prop="mineLevel" />-->
<!--      <el-table-column label="平台代数" align="center" prop="seniority" />-->
<!--      <el-table-column label="是否开启签到 0否 1是 实名认证通过后开启" align="center" prop="isSign" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->

<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['api:user:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['api:user:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="头像" prop="logo">
          <el-input v-model="form.logo" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入昵称" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="密码盐" prop="salt">
          <el-input v-model="form.salt" placeholder="请输入密码盐" />
        </el-form-item>
        <el-form-item label="交易密码" prop="txPassword">
          <el-input v-model="form.txPassword" placeholder="请输入交易密码" />
        </el-form-item>
        <el-form-item label="邀请码" prop="inviteCode">
          <el-input v-model="form.inviteCode" placeholder="请输入邀请码" />
        </el-form-item>
        <el-form-item label="真实名称" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实名称" />
        </el-form-item>
        <el-form-item label="身份证号" prop="cardNo">
          <el-input v-model="form.cardNo" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="身份证正面照" prop="cardFrontUrl">
          <el-input v-model="form.cardFrontUrl" placeholder="请输入身份证正面照" />
        </el-form-item>
        <el-form-item label="身份证反面照" prop="cardBackUrl">
          <el-input v-model="form.cardBackUrl" placeholder="请输入身份证反面照" />
        </el-form-item>
        <el-form-item label="手持照" prop="holdCardUrl">
          <el-input v-model="form.holdCardUrl" placeholder="请输入手持照" />
        </el-form-item>
        <el-form-item label="守护星级等级" prop="holdLevel">
          <el-input v-model="form.holdLevel" placeholder="请输入守护星级等级" />
        </el-form-item>
        <el-form-item label="矿工等级" prop="mineLevel">
          <el-input v-model="form.mineLevel" placeholder="请输入矿工等级" />
        </el-form-item>
        <el-form-item label="平台代数" prop="seniority">
          <el-input v-model="form.seniority" placeholder="请输入平台代数" />
        </el-form-item>
        <el-form-item label="是否开启签到 0否 1是 实名认证通过后开启" prop="isSign">
          <el-input v-model="form.isSign" placeholder="请输入是否开启签到 0否 1是 实名认证通过后开启" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, getUser, delUser, addUser, updateUser } from "@/api/api/user";

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobile: null,
        email: null,
        logo: null,
        nickName: null,
        password: null,
        salt: null,
        txPassword: null,
        inviteCode: null,
        realName: null,
        cardNo: null,
        cardFrontUrl: null,
        cardBackUrl: null,
        holdCardUrl: null,
        authStatus: null,
        status: null,
        holdLevel: null,
        mineLevel: null,
        seniority: null,
        isSign: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
        this.userList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mobile: null,
        email: null,
        logo: null,
        nickName: null,
        password: null,
        salt: null,
        txPassword: null,
        inviteCode: null,
        realName: null,
        cardNo: null,
        cardFrontUrl: null,
        cardBackUrl: null,
        holdCardUrl: null,
        authStatus: 0,
        status: 0,
        createTime: null,
        holdLevel: null,
        mineLevel: null,
        seniority: null,
        isSign: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getUser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户编号为"' + ids + '"的数据项？').then(function() {
        return delUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('api/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
